//implementation of a correlation attack
//this version uses 32-bit shift register
//each object has an lfsr
//before the attack the lfsr must be initiated 
//thus the length and the feedback polynomial must be set
//in the attack all initial states of the lfsr are tested
//for each state an lfsr output of the same length 
//as the keystream are generated
//the state that gives the output with the smallest distance 
//to the keystream are returned
#ifndef corrAttack_h
#define corrAttack_h
  
#include "word32.h"
#include "lfsr32.h"
#include "BitVector32.h"

class CorrAttack{
 private:
  lfsr32 lfsr;

 public:
  //default constructor
  CorrAttack(){}

  //constructor that takes the length of the LFSRs as input
  CorrAttack(int l){
    lfsr.resize(l);
  }

  //set the length
  void setLength(int l){
    lfsr.resize(l);
  }

  //initiate feedback polyniomial 
  void initPoly(word32 poly){
      lfsr.initPoly(poly);
  }

  //attack, return the initial state that generates the sequence
  //with the smallest distance to the keystream
  //initPoly and correct length must be set before calling attack
  unsigned long attack(BitVector32 keystream);

};

#endif
